package com.fxb.doraemon.human.rest;

import com.fxb.doraemon.human.entity.User;
import com.fxb.doraemon.human.service.UserService;
import com.fxb.doraemon.human.vo.UserQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户的controller
 *
 * @author fangjiaxiaobai@gmail.com
 * @since 2019-05-07
 */
@RestController
@RequestMapping("user")
@Api("用户接口")
public class UserController {

    private UserService userService;

    @GetMapping("/get/{id}")
    @ApiOperation("根据id获取用户")
    public User getUser(@PathVariable("id") String id) {
        return userService.get(id);
    }

    @PostMapping("save")
    @ApiOperation("保存用户")
    public Integer saveUser(@RequestBody User user) {
        return this.userService.saveUser(user);
    }

    @DeleteMapping("delete/{id}")
    @ApiOperation("删除用户")
    public Integer deleteUser(@PathVariable("id") String id) {
        return this.userService.deleteUser(id);
    }


    @PostMapping("update")
    @ApiOperation("更新用户")
    public Integer updateUser(@RequestBody User user) {
        return this.userService.updateUserById(user);
    }

    @PostMapping("getUserFully")
    @ApiOperation("查询用户列表(包括组织架构,岗位，公司等信息)")
    public List<UserQueryVo> getUserFully(@RequestBody User user) {
        return this.userService.getUserFully(user);
    }


    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
}
